C++ Threading
Table of Contents
1. std::this_thread namespace
this_thread provides functions for accessing the current executing thread.
std::this_thread::yield()hints the OS to reschedule the execution of threads, allowing other threads to run.sleep_for(time)blocks the current thread for at least the specifiedtime.sleep_until(time_point)blocks the execution of the current thread until specifiedtime_pointhas been reached. Thistime_pointis recommended to usestd::chrono::steady_clock.
2. std::jthread
Threads begin execution immediately upon construction of the associated thread object, starting from the function (top-level function) provided as constructor argument. The returned value of top-level function is ignored. If it terminates by throwing an exception, std::terminate() is called. The top-level function may also communicate its returned value or an exception to the caller via std::promise or by modifying shared variables.
join()- blocks the current thread until the thread identified by
*thisfinishes its execution.